package com.isunland.managesystem.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.MyCollectType;
import java.util.List;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/3/20 15:58
 */
public class MyCollectTypeListAdapter extends ArrayAdapter<MyCollectType> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-10-29 10:08:53 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final ImageView ivTopicForumImage;
    public final TextView tvTopicForumTypeName;

    private ViewHolder(LinearLayout rootView, ImageView ivTopicForumImage,
        TextView tvTopicForumTypeName) {
      this.rootView = rootView;
      this.ivTopicForumImage = ivTopicForumImage;
      this.tvTopicForumTypeName = tvTopicForumTypeName;
    }

    public static ViewHolder create(LinearLayout rootView) {
      ImageView ivTopicForumImage = (ImageView) rootView.findViewById(R.id.iv_topicForum_image);
      TextView tvTopicForumTypeName = (TextView) rootView.findViewById(R.id.tv_topicForum_typeName);
      return new ViewHolder(rootView, ivTopicForumImage, tvTopicForumTypeName);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_forum_topic_type, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    MyCollectType item = getItem(position);

    vh.tvTopicForumTypeName.setText(item.getCollecttypename());
    Drawable drawble = context.getResources().getDrawable(R.drawable.company_summarize);

    vh.ivTopicForumImage.setImageDrawable(drawble);

    return vh.rootView;
  }

  private LayoutInflater mInflater;
  private Context context;

  // Constructors
  public MyCollectTypeListAdapter(Context context, List<MyCollectType> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.context = context;
  }

  public MyCollectTypeListAdapter(Context context, MyCollectType[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.context = context;
  }
}

